﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DukeNUS.FacilitiesPlanning.FPSystem.Helpers
{

    /// <summary>
    /// Helper class that provides standard reference number formatting.
    /// </summary>
    public abstract class ReferenceNoFormatter
    {

        /// <summary>
        /// Transforms the specified numeric value into standardized reference number text.
        /// </summary>
        /// <param name="refno"></param>
        /// <returns></returns>
        public static string Format(int refno)
        { return Format(refno, 6); }

        /// <summary>
        /// Transforms the specified numeric value into standardized reference number text.
        /// </summary>
        /// <param name="refno"></param>
        /// <param name="prefix"></param>
        /// <returns></returns>
        public static string Format(int refno, string prefix)
        { return Format(refno, 6, prefix); }

        /// <summary>
        /// Transforms the specified numeric value into standardized reference number text.
        /// </summary>
        /// <param name="refno"></param>
        /// <param name="digits"></param>
        /// <returns></returns>
        public static string Format(int refno, int digits)
        { return Format(refno, digits, ""); }

        /// <summary>
        /// Transforms the specified numeric value into standardized reference number text.
        /// </summary>
        /// <param name="refno"></param>
        /// <param name="digits"></param>
        /// <param name="prefix"></param>
        /// <returns></returns>
        public static string Format(int refno, int digits, string prefix)
        {
            string formattedRefNo = "";

            string refNoText = refno.ToString();
            string zeros = "";

            while (refNoText.Length < digits)
            {
                zeros += "0";
                refNoText = zeros + refno.ToString();
            }

            if (!string.IsNullOrEmpty(prefix.Trim())) formattedRefNo = refNoText;
            else formattedRefNo = prefix.Trim().ToUpper() + (prefix.Trim().EndsWith("-") ? "" : "-") + refNoText;

            return formattedRefNo;
        }
    }

}